import { UserProfilesAPI } from "@/request/api";
export default {
    namespaced: true,
    state: {
        userInfo: {
            headImg: require("../../assets/img/service.848ec511.png"),
            nickName: "昵称",
            coin: 0
        },
        cartTotal: 0
    },
    mutations: {
        changeUserInfo(state, payload) {
            console.log("mutations", payload);
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal
        },
        initUserInfo(state) {
            state.userInfo = {
                    headImg: require("../../assets/img/service.848ec511.png"),
                    nickName: "昵称",
                    coin: 0
                },
                state.cartTotal = 0
        }
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            // 获取用户信息
            let res = await UserProfilesAPI();
            console.log("actions", res.data);
            // 更新state数据
            commit("changeUserInfo", res.data)
        }
    }
}